package main.chapter3

abstract class Person(open val age: Int) {
    //open的方法可以被复写
    open fun work() {

    }
}

class Developer(age: Int) : Person(age) {
    //open的属性也是可以复写的
    override val age: Int
        get() = super.age - 2

    //override复写父类方法
    override fun work() {
        //super访问父类
        super.work()
        println("我是码农，${age}岁，正在打代码")
    }
}

class Doctor(age: Int) : Person(age) {
    override fun work() {
        super.work()
        println("我是医生，${age}岁,正在给病人看病")
    }
}

fun main(args: Array<String>) {
    val person: Person = Developer(22)
    person.work()
    val person1: Person = Doctor(30)
    person1.work()
}

